<template>
  <div class="businessUnit">
    <div class="table">
      <el-table :data="tableData"
                border
                size="mini"
                :span-method="arraySpanMethod"
                :header-cell-style="{
                    background: '#C00000',
                    color: '#ffffff'
                }"
                v-loading="tableLoading">
        <BaseColumns :columns="columns">
            <template v-slot:class2="{ scope }">
                <span>{{scope.row.class2}}</span>
            </template>
        </BaseColumns>
      </el-table>
    </div>
  </div>
</template>

<script>
import { getMhDetailList } from "@/api/barCode/index";
export default {
  name: "HbWaveTable",
  components: {},
  props: {
    form: {
      type: Object,
      default: {}
    }
  },
  data () {
    return {
      tableLoading: false,
      tableData: [],
      columns: [],
      spanArr1: []
    };
  },
  computed: {},
  created () {
  },
  mounted () {
  },
  methods: {
    arraySpanMethod ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (this.spanArr1[rowIndex]) {
          return {
            rowspan: this.spanArr1[rowIndex],
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
    },
    getList () {
      this.tableLoading = true;
      getMhDetailList(this.form).then(res => {
        if (res.code == 200) {
          this.columns = [
            {
              label: "码号收入分细项展现",
              prop: "vertical_index_name",
              minWidth: "200",
              align: "left",
              fixed: 'left'
            },
            {
              label: "",
              prop: "class2",
              align: "left",
              fixed: 'left'
            },
            ...res.data.area.map(i => {
              const columnObj = {
                label: i,
                prop: i,
                width: "100",
                align: "center"
              }
              if (i == '环比') {
                columnObj.prop = 'amt'
              } else {
                columnObj.prop = 's' + i
              }
              return columnObj

            })
          ];

          this.tableData = res.data.data;
          let contactDot = 0;
          let spanArr1 = [];
          this.tableData.forEach((item, index) => {
            if (index === 0) {
              spanArr1.push(1);
            } else {
              if (
                item.class2 === this.tableData[index - 1].class2
              ) {
                spanArr1[contactDot] += 1;
                spanArr1.push(0);
              } else {
                contactDot = index;
                spanArr1.push(1);
              }
            }
          });
          this.spanArr1 = spanArr1;
        }
      }).finally(() => {
        this.tableLoading = false;
      })
    }
  }
};
</script>

<style scoped></style>
